//
//  Commont.swift
//  ZMWEIBO
//
//  Created by 庄猛 on 16/12/23.
//  Copyright © 2016年 BeiSheng. All rights reserved.
//

import UIKit

let App_Key = "2488312337"
let App_Secret = "3a96435aea2d8962ae8eb2158af5fa14"
let App_Redirect_url = "http://www.baidu.com"
let seachStr = "搜索你想要的宝贝"
var shopsDetailUrl : String?

var KScreenW : CGFloat = 99.99
var KScreenH : CGFloat = 99.99
var surpriseVC : SurpriseColumnsVC?
var vipPushTag = false
var addKey = true




var ZMNavMaxY : CGFloat = 64
var ZMTitlesViewH : CGFloat = 36
var ZMTabBarH : CGFloat = 49
var ZMMargin : CGFloat = 10


/*
 正则表达式，如果第一位不满足传继续往后匹配
 正则表达式中不要出现中文和空格
 
 
 */

func tabba(){
    //要匹配的字符串
    let str = "123456"
    
    //编写规则
    let patten = "[1-9][0-9]{4,15}"
    //创建正则表达式对象
    
    //caseInsensitive  忽略大小写  最常用
    //dotMatchesLineSeparators 允许 . 匹配任意字符，包括回车换行
    let regex = try! NSRegularExpression(pattern: patten, options: NSRegularExpression.Options.caseInsensitive)
    
    //根据规则匹配指定字符串中第一个符合规则的字符串，并且返回其范围
    let range = regex.rangeOfFirstMatch(in: str, options: NSRegularExpression.MatchingOptions.init(rawValue: 0), range: NSRange(location: 0, length: str.characters.count))
    print(range)
    
    //根据规则匹配指定字符串中第一个符合规则的字符串，并且返回一个NSTextCheckingResult
    let res = regex.firstMatch(in: str, options: NSRegularExpression.MatchingOptions.init(rawValue: 0), range:  NSRange(location: 0, length: str.characters.count))
    
    print(res?.range ?? "------")
    
    //根据规则匹配指定字符串中全部符合规则的字符串，并且返回一个[NSTextCheckingResult]数组
    let res1 = regex.matches(in: str, options: NSRegularExpression.MatchingOptions.init(rawValue: 0), range: NSRange(location: 0, length: str.characters.count))
    
    for temp in res1{
    
    print(temp.range)
    
    }
    
    
    //返回匹配个数若是零则无匹配元素
    let number = regex.numberOfMatches(in: str, options: NSRegularExpression.MatchingOptions.init(rawValue: 0), range: NSRange(location: 0, length: str.characters.count))
    
    print(number)
}


// MARK:- 正则练习
func text(){
    
    let str = "@庖丁解牛: ffdsfd[哈哈],#彩票# http://www.baidu.om"
    //规则
    //电话号码
    let pattern = "[1][0-9]{10}"
    
    //表情符号
    let pattern1 = "\\[.*?\\]"
    
    //@某人
    let pattern2 = "@.*?:"
    
    //话题
    let pattern3 = "#.*?#"
    
    //链接
    let pattern4 = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?"
    
    
    _ = pattern + "|" + pattern1 + "|" +  pattern2 + "|" +  pattern3 + "|" + pattern4 + "|"
    
    
    //链接（原生）
    
    
    let detetor = try! NSDataDetector(types: NSTextCheckingTypes(NSTextCheckingResult.CheckingType.link.rawValue))
    
    let arr = detetor.matches(in: str, options: NSRegularExpression.MatchingOptions.init(rawValue: 0), range: NSRange(location: 0, length: str.characters.count))
    
    for res in arr{
    
//    print(str.substring(with: res.range))
    
    print(res)
    }
}







//        [SVProgressHUD showWithStatus:@"正在获取最新版本信息"];
//        [[NetworkTools shareNetworkTools] sendRequestWithHttpMethod:GET_METHOD URLPath:@"mobile/index.php?c=index&a=get_version" parameters:nil completionHandler:^(id responseObject, NSError *error) {
//
//            if (!error) {
//
//                [SVProgressHUD dismiss];
//
//                self.ios_version = responseObject[@"datas"][@"ios_version"];
//
//                self.ios_url = responseObject[@"datas"][@"ios_url"];
//
//                [self compareNewVersion];
//            }else{
//
//                [SVProgressHUD showErrorWithStatus:error.domain];
//
//            }
//
//
//        }];






//- (void)compareNewVersion{
//
//    NSString *last = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
//
//    if ([self.ios_version compare:last] == NSOrderedDescending) {
//
//
//        UIAlertController *contr = [UIAlertController alertControllerWithTitle:nil message:@"检测到新版本,是否前往应用商店下载?" preferredStyle:UIAlertControllerStyleAlert];
//
//        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"前往" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//
//            if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:self.ios_url]]) {
//
//                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:self.ios_url]];
//            }
//
//
//
//        }];
//
//
//        UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//
//
//        }];
//
//
//        [contr addAction:action2];
//
//        [contr addAction:action1];
//
//        [self presentViewController:contr animated:YES completion:nil];
//
//
//    }else{
//
//
//        [SVProgressHUD showInfoWithStatus:@"当前已是最新版本!"];
//
//
//    }
//
//
//
//
//
//}







